import React, { memo } from 'react'
import { Checkbox, Radio } from 'antd'

interface IProps {
  type: 'checkbox' | 'radio' | string;
  rowKey: string;
  checked: boolean;
  onChange(checked: boolean, rowKey: string): void;
  disabled?: boolean;
}

export default memo(({ type, checked, disabled, rowKey, onChange }: IProps) => {
  const Children = type === 'checkbox' ? Checkbox : Radio;
  return (
    <Children
      onChange={() => onChange(!checked, rowKey)}
      checked={checked}
      disabled={disabled} />
  )
})